package com.good.child.widgets.addressPicker;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Create on: 2024/2/28
 * by Mr.Zhu
 * Description: TODO
 */
public class AddressBean implements Serializable {
    private String id;
    private String areaName;
    private String parentStatId;
    private int statGrade;
    private boolean status;
    private List<AddressBean> children;

    public AddressBean() {
    }

    public AddressBean(String id, String areaName, List<AddressBean> children) {
        this.id = id;
        this.areaName = areaName;
        this.children = children;
    }

    public AddressBean(AddressBean parent, AddressBean bean, boolean copyChild, String city) {
        this.areaName = bean.areaName;
        this.status = bean.status;
        this.id = bean.id;
        if (parent == null || copyChild) {
            this.children = copy(bean, copyChild, city);
        }
    }

    private List<AddressBean> copy(AddressBean bean, boolean copyChild, String city) {
        List<AddressBean> children = bean.children;
        if (children != null) {
            List<AddressBean> temp = new ArrayList<>();
            final int size = children.size();
            for (int i = 0; i < size; i++) {
                AddressBean addressBean = children.get(i);
                if (city != null) {
                    if (addressBean.getAreaName().equals(city)) {
                        temp.add(new AddressBean(bean, addressBean, copyChild,null));
                        break;
                    }
                } else {
                    temp.add(new AddressBean(bean, addressBean, copyChild,city));
                }
            }
            return temp;
        }
        return null;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public String getAreaName() {
        return areaName;
    }

    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }

    public String getParentStatId() {
        return parentStatId;
    }

    public void setParentStatId(String parentStatId) {
        this.parentStatId = parentStatId;
    }

    public int getStatGrade() {
        return statGrade;
    }

    public void setStatGrade(int statGrade) {
        this.statGrade = statGrade;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public List<AddressBean> getChildren() {
        return children;
    }

    public void setChildren(List<AddressBean> children) {
        this.children = children;
    }
}
